layui.define(["table", "element"], function (exports) {
  var $ = layui.$,
    table = layui.table,
    element = layui.element;

  $(function () {
    var status =
      layui.sessionData("status").key == undefined
        ? "3"
        : layui.sessionData("status").key;
    switch (status) {
      case "1":
        element.tabChange("technicalRevieTab", "1");
        position = "#guardianshipProgram";
        toolbarOperatee = "#guardianshipOpera";
        OperateeWidth = 350;
        hidecolumn = true;

        break;
      case "2":
        element.tabChange("technicalRevieTab", "2");
        position = "#technicalReConsultation";
        toolbarOperatee = "#technicalReConsultationOprea";
        OperateeWidth = 525;
        hidecolumn = false;
        break;
      case "3":
        element.tabChange("technicalRevieTab", "3");
        position = "#technicalReview";
        toolbarOperatee = "#technicalReviewOprea";
        OperateeWidth = 525;
        hidecolumn = true;
        break;
      case "4":
        element.tabChange("technicalRevieTab", "4");
        position = "#protectionScheme";
        toolbarOperatee = "#protectionSchemeOprea";
        OperateeWidth = 260;
        hidecolumn = true;
        break;
      case "5":
        element.tabChange("technicalRevieTab", "5");
        position = "#combinedTransformation";
        toolbarOperatee = "#combinedTransformationOpra";
        OperateeWidth = 320;
        hidecolumn = true;
        break;
    }
    getList(position, status, toolbarOperatee, OperateeWidth, hidecolumn);
  });

  // getList("#technicalReview", "", "#technicalReviewOprea", 530, true);
  element.on("tab(technicalRevieTab)", function (data) {
    layui.sessionData("status", {
      key: "key",
      value: $(this).attr("data-status"),
    });
    var status = layui.sessionData("status").key;
    // var position = "#technicalReview";
    // var toolbarOperatee = "#technicalReviewOprea";
    // var OperateeWidth = 330;
    switch (status) {
      case "1":
        position = "#guardianshipProgram";
        toolbarOperatee = "#guardianshipOpera";
        OperateeWidth = 350;
        hidecolumn = true;
        break;
      case "2":
        position = "#technicalReConsultation";
        toolbarOperatee = "#technicalReConsultationOprea";
        OperateeWidth = 525;
        hidecolumn = false;
        break;
      case "3":
        position = "#technicalReview";
        toolbarOperatee = "#technicalReviewOprea";
        OperateeWidth = 525;
        hidecolumn = true;
        break;
      case "4":
        position = "#protectionScheme";
        toolbarOperatee = "#protectionSchemeOprea";
        OperateeWidth = 260;
        hidecolumn = true;
        break;
      case "5":
        position = "#combinedTransformation";
        toolbarOperatee = "#combinedTransformationOpra";
        OperateeWidth = 320;
        hidecolumn = true;
        break;
    }
    getList(position, status, toolbarOperatee, OperateeWidth, hidecolumn);
  });
  function getList(
    position,
    status,
    toolbarOperatee,
    OperateeWidth,
    hidecolumn
  ) {
    table.render({
      elem: position,
      skin: "nob", // 无边框风格
      height: "full-220",
      url: base_url + "/report/selectIssueProjectList", //模拟接口
      headers: {
        Accept: "application/json; charset=utf-8",
        Authorization: layui.sessionData("userToken").key,
      },
      method: "post",
      contentType: "application/json",
      parseData: function (res) {
        return {
          code: 0,
          count: res.data.projectList.total,
          data: res.data.projectList.list,
          msg: res.data.message,
        };
      },
      cols: [
        [
          // {
          //   field: "id",
          //   align: "center",
          //   title: "序号",
          //   width: 80,
          // },
          { field: "no", title: "编号", align: "center", width: 130 },
          {
            field: "projectName",
            title: "工程名称",
            align: "center",
            width: 400,
            event: "projectName",
            templet: function (item) {
              return (
                "<div title=" +
                item.projectName +
                " class='whiteSpace'>" +
                item.projectName +
                "</div>"
              );
            },
          },
          {
            field: "flowStatus",
            title: "状态",
            align: "center",
            templet: function (item) {
              return (
                "<div title=" +
                item.flowStatus +
                " class='whiteSpace'>" +
                item.flowStatus +
                "</div>"
              );
            },
          },
          // {
          //   field: "type",
          //   title: "类别",
          //   align: "center",
          //   width: 130,
          //   hide: hidecolumn,
          // },
          {
            field: "reviewStatus",
            title: "待办描述",
            align: "center",
            width: 260,
            // templet: "#agentDescription",
          },
          {
            field: "insertDate",
            title: "创建时间",
            width: 210,
            align: "center",
          },
          {
            title: "操作",
            width: OperateeWidth,
            align: "center",
            // fixed: "right",
            toolbar: toolbarOperatee,
          },
        ],
      ],
      page: true,
      limit: 5,
      limits: [5, 10, 15, 20, 25, 30],
      text: { none: "无数据" },
      where: { selectType: status, agenda: "0" },
      done: function (res, curr, count) {
        // 表格渲染完成之后的回调
        var that = this.elem.next();
        res.data.forEach(function (item, index) {
          //console.log(item.empName);item表示每列显示的数据
          if (index % 2 == 0) {
            var tr = that
              .find(".layui-table-box tbody tr[data-index='" + index + "']")
              .css("background-color", "transparent");
          } else {
            var tr = that
              .find(".layui-table-box tbody tr[data-index='" + index + "']")
              .css("background", "#EDF2FB");
          }
        });
      },
    });
  }
  exports("contlist", {});
});
